package org.jeecg.modules.api.controller.music.artist;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.api.vo.artist.ArtistAlbumVo;
import org.jeecg.modules.api.vo.artist.ArtistDetailVo;
import org.jeecg.modules.music.entity.MusArtist;
import org.jeecg.modules.music.service.IMusArtistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags="音乐系统")
@RestController
@RequestMapping("api/mus/")
public class ArtistsCenterAPIController {

    @Autowired
    private IMusArtistService musArtistService;

    @ApiOperation("API-歌手外部接口-获取歌手详情 /artist/detail")
    @RequestMapping(value = "/artist/detail", method = RequestMethod.GET)
    public Result queryArtistDetail(@RequestParam(name="id",required=true)String id){
        Map<String, Object> resultMap = new HashMap<>();
        ArtistDetailVo artist = musArtistService.queryArtistDetail(id);
        resultMap.put("artist",artist);
        return Result.ok(resultMap);
    }


    @ApiOperation("API-歌手外部接口-获取歌手专辑 /artist/album")
    @RequestMapping(value = "/artist/albums", method = RequestMethod.GET)
    public Result queryArtistAlbums(@RequestParam(name="id",required=true)String id,@RequestParam(name="limit", defaultValue="12") Integer limit,@RequestParam(name="offset", defaultValue="0")  Integer offset){
        Map<String, Object> resultMap = new HashMap<>();
        List<ArtistAlbumVo> artistAlbums = musArtistService.queryArtistAlbums(id,limit,offset);
        ArtistDetailVo artist = musArtistService.queryArtistDetail(id);
        resultMap.put("artist",artist);
        resultMap.put("hotAlbums",artistAlbums);
        return Result.ok(resultMap);
    }

    @ApiOperation("API-歌手外部接口-获取歌手介绍 /artist/desc")
    @RequestMapping(value = "/artist/desc", method = RequestMethod.GET)
    public Result queryArtistDesc(@RequestParam(name="id",required=true) String id){
        Map<String, Object> resultMap = new HashMap<>();
        MusArtist artist = musArtistService.getById(id);
        resultMap.put("artistInfo",artist);
        return Result.ok(resultMap);
    }

    @ApiOperation("API-歌手外部接口-获取相似歌手 /simi/artist")
    @RequestMapping(value = "/simi/artist", method = RequestMethod.GET)
    public Result querySimiArtist(@RequestParam(name="id",required=true) String id){
        Map<String, Object> resultMap = new HashMap<>();

        List<ArtistDetailVo> artists = musArtistService.querySimiSingers(id);
        resultMap.put("artists",artists);
        return Result.ok(resultMap);
    }

    @ApiOperation("API-歌手外部接口-热门歌手")
    @RequestMapping(value = "/hot/artists", method = RequestMethod.GET)
    public Result queryHotSingers(@RequestParam(name="offset", defaultValue="1") Integer offset,
                                  @RequestParam(name="limit", defaultValue="110") Integer limit ){
        List<ArtistDetailVo> artists = musArtistService.queryHotSingers(offset,limit);
        Map<String,Object> map = new HashMap<>();
        map.put("artists",artists);
        return Result.ok(map);
    }

    @ApiOperation("API-歌手外部接口-歌手相关")
    @RequestMapping(value = "/artists/list", method = RequestMethod.GET)
    public Result queryArtistsList(
                                   @RequestParam(name = "type",required = false) Integer type,
                                   @RequestParam(name = "area",required = false) Integer area,
                                   @RequestParam(name = "initial",required = false) String initial,
                                   @RequestParam(name="offset", defaultValue="1") Integer offset,
                                   @RequestParam(name="limit", defaultValue="110") Integer limit
                                   ) {

        List<ArtistDetailVo> artists = musArtistService.querySingersList(type,area,initial,offset,limit);
        Map<String,Object> map = new HashMap<>();
        map.put("artists",artists);
        return Result.ok(map);
    }
}
